﻿using System;
using System.Linq;
using SuperSocket.Command;
using SuperSocket.ProtoBase;
using SuperSocketV2Sample.MultipleServer.Commands;
using SuperSocketV2Sample.MultipleServer.Server;

namespace SS.MultipleServer.Commands;

/// <summary>
/// 加法命令
/// </summary>
[Command(Key = "ADD")]
[AsyncKeyUpperCommandFilter]
public abstract class AddCommand : BaseCommand
{
    protected override string GetResult(StringPackageInfo package)
    {
        string result;
        try
        {
            result = package.Parameters
                // ReSharper disable once ConvertClosureToMethodGroup
                .Select(t => int.Parse(t))
                .Sum()
                .ToString();
        }
        catch (Exception e)
        {
            result = e.Message;
        }

        return result;
    }
}